/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.avn;

import android.os.IBinder;
import android.os.RemoteException;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.StatusBarNotification;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.util.Log;
import android.util.Slog;
import android.graphics.PixelFormat;
import android.app.StatusBarManager;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.view.Gravity;
import android.view.MotionEvent;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.systemui.statusbar.ActivatableNotificationView;
import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.R;
import android.content.res.Resources;
import android.content.BroadcastReceiver;
import android.content.IntentFilter;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.widget.ImageView;
import android.app.Instrumentation;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import com.common.util.MyCmd;
import com.common.util.AppConfig;

/*
 * Status bar implementation for "large screen" products that mostly present no on-screen nav
 */

public class AVNStatusBar extends BaseStatusBar implements View.OnKeyListener,
		View.OnFocusChangeListener, View.OnClickListener {
	static final String TAG = "AVNStatusBar";
	// public static final boolean DEBUG = BaseStatusBar.DEBUG;
	public static final boolean DEBUG = true;

	private AVNStatusBarView mStatusBar = null;

	// tracking calls to View.setSystemUiVisibility()
	int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;

	int mNaturalBarHeight = -1;

	public int getStatusBarHeight() {
		if (mNaturalBarHeight < 0) {
			final Resources res = mContext.getResources();
			mNaturalBarHeight = res
					.getDimensionPixelSize(R.dimen.status_bar_height);
		}
		return mNaturalBarHeight;
	}

	static final int[] WIFI_SIGNAL_STRENGTH = { R.drawable.wifi_0,
			R.drawable.wifi_1, R.drawable.wifi_2, R.drawable.wifi_3,
			R.drawable.wifi_4 };

	static final int WIFI_LEVEL_COUNT = WIFI_SIGNAL_STRENGTH.length;

	// add wifi icon
	private ImageView wifi_image;

	private void initWifi() {
		// WifiManager wifi_service = (WifiManager)
		// getSystemService(WIFI_SERVICE);
		wifi_image = (ImageView) mStatusBar.findViewById(R.id.wifi_signal);

		IntentFilter wifiIntentFilter;

		wifiIntentFilter = new IntentFilter();
		wifiIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
		wifiIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);

		mContext.registerReceiver(wifiIntentReceiver, wifiIntentFilter);
	}

	private BroadcastReceiver wifiIntentReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {

			if (intent.getAction()
					.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {

				int wifi_state = intent.getIntExtra(
						WifiManager.EXTRA_WIFI_AP_STATE, 0);
				switch (wifi_state) {
				case WifiManager.WIFI_STATE_DISABLED:
					wifi_image.setVisibility(View.GONE);
					break;
				case WifiManager.WIFI_STATE_ENABLED:
					wifi_image.setVisibility(View.VISIBLE);
					break;
				}
			} else if (intent.getAction().equals(
					WifiManager.NETWORK_STATE_CHANGED_ACTION)) {

				NetworkInfo info = intent
						.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);

				if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
					wifi_image.setImageResource(R.drawable.wifi_null);
				} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {

					WifiManager wifiManager = (WifiManager) context
							.getSystemService(Context.WIFI_SERVICE);
					WifiInfo wifiInfo = wifiManager.getConnectionInfo();

					int ssid = wifiInfo.getRssi();

					int level = WifiManager.calculateSignalLevel(ssid,
							WIFI_LEVEL_COUNT);

					wifi_image.setImageResource(WIFI_SIGNAL_STRENGTH[level]);
				}

			}
		}
	};

	ImageView mHome;
	ImageView mBack;
	ImageView mCar;

	View mViewFocus;
	boolean mFocus = true;
public static final String EXTRA_COMMON_CMD = "cmd";
	public static final String EXTRA_COMMON_DATA = "data";
		public static final String BROADCAST_CAR_SERVICE_RECEIVE_DATA = "com.my.car.service.SET_DATA";
			public static final int CMD_CAR_SERVICE_SET_CAR_SCREEN = 22;
	public void onFocusChange(View view, boolean b) {
		if (b)
			mViewFocus = view;
	}

	public void onClick(View v) {
	
		switch (v.getId()) {
		case R.id.home:{
		Intent i = new Intent(BROADCAST_CAR_SERVICE_RECEIVE_DATA);
				i.putExtra(EXTRA_COMMON_CMD, CMD_CAR_SERVICE_SET_CAR_SCREEN);
						i.putExtra(EXTRA_COMMON_DATA, 2);
						i.setPackage("com.my.out");
								mContext.sendBroadcast(i);


			}
		//	doKeyEvent(KeyEvent.KEYCODE_HOME);
			break;
		case R.id.back:
			doKeyEvent(KeyEvent.KEYCODE_BACK);
			break;
	
		}
	}

	public boolean onKey(View v, int keyCode, KeyEvent event) {
	
		

		return false;
	}

	private void initButton() {
		mHome = (ImageView) mStatusBar.findViewById(R.id.home);
		mBack = (ImageView) mStatusBar.findViewById(R.id.back);
		mCar = (ImageView) mStatusBar.findViewById(R.id.car);

		mHome.setOnFocusChangeListener(this);
		mBack.setOnFocusChangeListener(this);
		mCar.setOnFocusChangeListener(this);

		mHome.setOnKeyListener(this);
		mBack.setOnKeyListener(this);
		mCar.setOnKeyListener(this);

		mHome.setOnClickListener(this);
		mBack.setOnClickListener(this);
		mCar.setOnClickListener(this);

	}
	private int[] FOCUS_BUTTON = new int[] { R.id.home, R.id.back, R.id.car};

	private void setAllFocus(boolean b) {

		if (!b) {
			for (int i : FOCUS_BUTTON) {
				mStatusBar.findViewById(i).setOnFocusChangeListener(null);
				mStatusBar.findViewById(i).clearFocus();
			}

		}

		for (int i : FOCUS_BUTTON) {
			mStatusBar.findViewById(i).setFocusable(b);
		}

		if (b) {
			for (int i : FOCUS_BUTTON) {
				mStatusBar.findViewById(i).setOnFocusChangeListener(this);
			}
		}
	}

	private boolean mIsInBackKey = false;
	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 0:
				doKeyEvent(4);
				break;
			//case 1:
			//	doStatusBarFocus(false, false);

			//	break;
			case 2:
				
				//Log.e(TAG, "mIsInBackKey:"+mIsInBackKey);
				if (mIsInBackKey){
					mIsInBackKey = false;
					doStatusBarFocus(true, false);
				}
				break;
				
				case 3:
					//Log.e(TAG, "mHandler:"+mIsInBackKey);
				doBackKey();


				break;
				case 4:
				setAllFocus(false);


				break;
			}

		}
	};

	private boolean mIsCarApp = false;
	private boolean mIsHomeApp = false;

	private void doStatusBarFocus(boolean focus, boolean broadcast) {
/*		if (mFocus == focus)
			return;

		mFocus = focus;
		Intent i = new Intent(MyCmd.BROADCAST_STATUS_BAR_GET_DATA);
		int cmd = 0;

		if (!focus) {
			mLp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
			mLp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
			cmd = MyCmd.CMD_STATUS_BAR_HIDE;

		} else {
			mLp.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
			mLp.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;

			cmd = MyCmd.CMD_STATUS_BAR_SHOW;

		}

		mWindowManager.updateViewLayout(mStatusBar, mLp);

		if (broadcast) {
			i.putExtra(MyCmd.EXTRA_COMMON_CMD, cmd);
			mContext.sendBroadcast(i);
		}
*/
	}

	private void doBackKey() {
	//	Log.e(TAG, "doBackKey:"+mFocus);
		if (mFocus) {
			doStatusBarFocus(false, false);
			mIsInBackKey = true;
			// mHandler.sendEmptyMessageDelayed(2, 50);
			mHandler.sendEmptyMessageDelayed(0, 100);
			mHandler.sendEmptyMessageDelayed(2, 200);
		} else {
			doKeyEvent(KeyEvent.KEYCODE_BACK);
		}

	}

	private void doCmd(int cmd) {
		switch (cmd) {
		case MyCmd.CMD_STATUS_BAR_SHOW:
			setAllFocus(true);
			if (mViewFocus != null) {
				mViewFocus.requestFocus();
			}
			doStatusBarFocus(true, true);
			break;
		case MyCmd.CMD_STATUS_BAR_HIDE:
			setAllFocus(false);
			if (mViewFocus != null) {
				mViewFocus.clearFocus();
			}
			doStatusBarFocus(false, true);
			break;
		case MyCmd.CMD_STATUS_BAR_BACK_KEY:
			//Log.e(TAG, "doCmd:"+mFocus);
			doBackKey();
			break;

		}
	}

	private BroadcastReceiver mReceiver = null;

	private void registerListener() {
		if (mReceiver == null) {
			mReceiver = new BroadcastReceiver() {
				@Override
				public void onReceive(Context context, Intent intent) {
					String action = intent.getAction();
					//Log.d(TAG, action+"!");
					if (action.equals(MyCmd.BROADCAST_STATUS_BAR_SET_DATA)) {
						int i = intent.getIntExtra(MyCmd.EXTRA_COMMON_CMD, 0);
						doCmd(i);

					}
					else if (action.equals(MyCmd.BROADCAST_ACTIVITY_STATUS)) {
						String s = intent
								.getStringExtra(MyCmd.EXTRA_COMMON_CMD);
						int data =  intent
								.getIntExtra(MyCmd.EXTRA_COMMON_DATA, 0);


						boolean isCarApp = AppConfig.isSystemApp(s);
						boolean isHomeApp = AppConfig.isHomeApp(s);
 	mIsInBackKey = false;/*
						if ( isHomeApp){
							mHome.setVisibility(View.GONE);
							mBack.setVisibility(View.GONE);
							mCar.setVisibility(View.VISIBLE);
						} else{
							mHome.setVisibility(View.VISIBLE);						
							mBack.setVisibility(View.VISIBLE);
							mCar.setVisibility(View.GONE);
						}*/

							if (isCarApp && mFocus){
								doStatusBarFocus(false, false);
								setAllFocus(false);
							} else if (!isCarApp && !mFocus && !mFullScreen){
								doStatusBarFocus(true, false);
								setAllFocus(true);
							}
							



					mIsCarApp = isCarApp;
						mIsHomeApp = isHomeApp;

						//Log.e(TAG, s+":"+data+":"+mIsCarApp);
						
					}

				}
			};
			IntentFilter iFilter = new IntentFilter();
			iFilter.addAction(MyCmd.BROADCAST_STATUS_BAR_SET_DATA);
			iFilter.addAction(MyCmd.BROADCAST_ACTIVITY_STATUS);
			mContext.registerReceiver(mReceiver, iFilter);
		}
	}

	private static int mKey = KeyEvent.KEYCODE_UNKNOWN;
	private static Instrumentation mInst;

	public static void doKeyEvent(int value) {
		mKey = value;
		Thread t = new Thread(new Runnable() {
			@Override
			public void run() {
				if (mKey != KeyEvent.KEYCODE_UNKNOWN) {
					try {
						if (mInst == null) {
							mInst = new Instrumentation();
						}
						mInst.sendKeyDownUpSync(mKey);
					} catch (Exception e) {
						Log.e("Exception when sendPointerSync", e.toString());
					}
					mKey = KeyEvent.KEYCODE_UNKNOWN;
				}
			}
		});
		t.start();
	}

	WindowManager.LayoutParams mLp;

	private void addStatusBar() {
		if (DEBUG)
			Slog.d(TAG, "addStatusBar11: " + mStatusBar);
		if (mStatusBar == null) {
			return;
			// createAndAddWindows();
		}

		int barHeight = getStatusBarHeight();

		mLp = new WindowManager.LayoutParams(LayoutParams.MATCH_PARENT,
				barHeight, WindowManager.LayoutParams.TYPE_STATUS_BAR,
				WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
						| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |

						WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING,
				PixelFormat.TRANSLUCENT);

		mLp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
		mLp.gravity = Gravity.TOP;
		mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
		mLp.setTitle("StatusBar");
		mLp.packageName = mContext.getPackageName();
		// mStatusBarView = statusBarView;
		// mBarHeight = barHeight;
		mWindowManager.addView(mStatusBar, mLp);

		initWifi();
		initButton();
	//	registerListener();

	}

	public void notifyUiVisibilityChanged(int vis) {
		try {
			mWindowManagerService.statusBarVisibilityChanged(vis);
		} catch (RemoteException ex) {
		}

		Slog.d(TAG, "notifyUiVisibilityChanged: " + vis);
	}

	private final Runnable mAutohide = new Runnable() {
		@Override
		public void run() {
			int requested = mSystemUiVisibility & ~STATUS_OR_NAV_TRANSIENT;
			if (mSystemUiVisibility != requested) {
				notifyUiVisibilityChanged(requested);
			}
		}
	};

	private boolean mAutohideSuspended;
	private static final int STATUS_OR_NAV_TRANSIENT = View.STATUS_BAR_TRANSIENT
			| View.NAVIGATION_BAR_TRANSIENT;
	private static final long AUTOHIDE_TIMEOUT_MS = 3000;

	private int mStatusBarMode;

	private void resumeSuspendedAutohide() {
		if (mAutohideSuspended) {
			scheduleAutohide();
			// mHandler.postDelayed(mCheckBarModes, 500); // longer than home ->
			// launcher
		}
	}

	private void suspendAutohide() {
		mHandler.removeCallbacks(mAutohide);
		// mHandler.removeCallbacks(mCheckBarModes);
		mAutohideSuspended = (mSystemUiVisibility & STATUS_OR_NAV_TRANSIENT) != 0;
		Slog.d(TAG, "suspendAutohide: ");
	}

	private void cancelAutohide() {
		mAutohideSuspended = false;
		mHandler.removeCallbacks(mAutohide);
		Slog.d(TAG, "cancelAutohide: ");
	}

	private void scheduleAutohide() {
		cancelAutohide();
		mHandler.postDelayed(mAutohide, AUTOHIDE_TIMEOUT_MS);
	}

	private void checkUserAutohide(View v, MotionEvent event) {
		if ((mSystemUiVisibility & STATUS_OR_NAV_TRANSIENT) != 0 // a transient
																	// bar is
																	// revealed
				&& event.getAction() == MotionEvent.ACTION_OUTSIDE // touch
																	// outside
																	// the
																	// source
																	// bar
				&& event.getX() == 0 && event.getY() == 0 // a touch outside
															// both bars
		) {
			userAutohide();
		}
	}

	private void userAutohide() {
		cancelAutohide();
		mHandler.postDelayed(mAutohide, 350); // longer than app gesture -> flag
												// clear
												Slog.d(TAG, "userAutohide: ");
	}

	@Override
	public void start() {
		super.start(); // call createAndAddWindows()

		if (DEBUG)
			Slog.d(TAG, "start");

		addStatusBar();
		// addMultiWindowControlBar();
	}

	@Override
	public void addIcon(String slot, int index, int viewIndex,
			StatusBarIcon icon) {
	}

	@Override
	public void updateIcon(String slot, int index, int viewIndex,
			StatusBarIcon old, StatusBarIcon icon) {
	}

	@Override
	public void removeIcon(String slot, int index, int viewIndex) {
	}

	@Override
	public void addNotification(StatusBarNotification notification,
			RankingMap ranking) {
	}

	@Override
	protected void updateNotificationRanking(RankingMap ranking) {
	}

	@Override
	public void removeNotification(String key, RankingMap ranking) {
	}

	@Override
	public void disable(int state, boolean animate) {
		Slog.d(TAG, "disable: " + state);
	}

	@Override
	public void animateExpandNotificationsPanel() {
	}

	@Override
	public void animateCollapsePanels(int flags) {
	}

	@Override
	public void setSystemUiVisibility(int vis, int mask) {
		if (DEBUG)
			Slog.d(TAG, "setSystemUiVisibility: " + vis);

		if ((vis & View.STATUS_BAR_VISIBLE) == View.STATUS_BAR_VISIBLE) {
			mStatusBar.setVisibility(View.VISIBLE);
		} else if ((vis & View.STATUS_BAR_HIDDEN) == View.STATUS_BAR_HIDDEN) {
			mStatusBar.setVisibility(View.GONE);
		}
		// notifyUiVisibilityChanged(vis);

		/*
		 * if ((vis & View.MULTIWINDOW_CONTROL_VISIBLE) ==
		 * View.MULTIWINDOW_CONTROL_VISIBLE) {
		 * mControlBar.setVisibility(View.VISIBLE); } else if ((vis &
		 * View.MULTIWINDOW_CONTROL_HIDDEN) == View.MULTIWINDOW_CONTROL_HIDDEN)
		 * { mControlBar.setVisibility(View.GONE); }
		 * 
		 * if ((vis & View.MULTIWINDOW_MINILAUNCHER_VISIBLE) ==
		 * View.MULTIWINDOW_MINILAUNCHER_VISIBLE) {
		 * mMiniLauncher.setVisibility(View.VISIBLE); } else if ((vis &
		 * View.MULTIWINDOW_MINILAUNCHER_HIDDEN) ==
		 * View.MULTIWINDOW_MINILAUNCHER_HIDDEN) {
		 * mMiniLauncher.setVisibility(View.GONE); }
		 * 
		 * if ((vis & View.MULTIWINDOW_DRAG_VISIBLE) ==
		 * View.MULTIWINDOW_DRAG_VISIBLE) {
		 * mDragControl.setVisibility(View.VISIBLE); } else if ((vis &
		 * View.MULTIWINDOW_DRAG_HIDDEN) == View.MULTIWINDOW_DRAG_HIDDEN) {
		 * mDragControl.setVisibility(View.GONE); }
		 * 
		 * if ((vis & View.MULTIWINDOW_FLOATING_VISIBLE) ==
		 * View.MULTIWINDOW_FLOATING_VISIBLE) {
		 * mFloatingControl.setVisibility(View.VISIBLE); } else if ((vis &
		 * View.MULTIWINDOW_FLOATING_HIDDEN) ==
		 * View.MULTIWINDOW_FLOATING_HIDDEN) {
		 * mFloatingControl.setVisibility(View.GONE); }
		 */
	}

	@Override
	public void topAppWindowChanged(boolean visible) {
	}

	@Override
	public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
			boolean showImeSwitcher) {
	}

	@Override
	public void toggleRecentApps() {
	}
	boolean mFullScreen = false;
	@Override
	// CommandQueue
	public void setWindowState(int window, int state) {
		 mFullScreen = (state != StatusBarManager.WINDOW_STATE_SHOWING);
				
		Slog.d(TAG, "setWindowState: " + state+mFullScreen);
		if (mFullScreen){
			if (mFocus){
				doStatusBarFocus(false, true);
			}
		} else {

		}
	}

	@Override
	// CommandQueue
	public void buzzBeepBlinked() {
	}

	@Override
	// CommandQueue
	public void notificationLightOff() {
	}

	@Override
	// CommandQueue
	public void notificationLightPulse(int argb, int onMillis, int offMillis) {
	}

	@Override
	protected WindowManager.LayoutParams getSearchLayoutParams(
			LayoutParams layoutParams) {
		return null;
	}

	@Override
	protected void haltTicker() {
	}

	@Override
	protected void setAreThereNotifications() {
	}

	@Override
	protected void updateNotifications() {
	}

	@Override
	protected void tick(StatusBarNotification n, boolean firstTime) {
	}

	@Override
	protected void updateExpandedViewPos(int expandedPosition) {
	}

	@Override
	protected boolean shouldDisableNavbarGestures() {
		return true;
	}

	public View getStatusBarView() {
		Slog.d(TAG, "getStatusBarView!!: ");
		return mStatusBar;
	}

	@Override
	public void resetHeadsUpDecayTimer() {
	}

	@Override
	public void scheduleHeadsUpOpen() {
	}

	@Override
	public void scheduleHeadsUpEscalation() {
	}

	@Override
	public void scheduleHeadsUpClose() {
	}

	@Override
	protected int getMaxKeyguardNotifications() {
		return 0;
	}

	@Override
	public void animateExpandSettingsPanel() {
	}

	@Override
	protected void createAndAddWindows() {
		mStatusBar = (AVNStatusBarView) View.inflate(mContext,
				R.layout.avn_status_bar, null);

	}

	@Override
	protected void refreshLayout(int layoutDirection) {
	}

	@Override
	public void onActivated(ActivatableNotificationView view) {
	}

	@Override
	public void onActivationReset(ActivatableNotificationView view) {
	}

	@Override
	public void showScreenPinningRequest() {
	}

	// will be delete . by
	// allen..................................................................
	//
	//
	private MultiWindowControlBarView mControlBar = null;

	private MiniLauncherView mMiniLauncher = null;

	private MultiWindowDragControlView mDragControl = null;

	private FloatingWindowControlView mFloatingControl = null;

	private void addMultiWindowControlBar() {
		if (DEBUG)
			Slog.d(TAG, "addMultiWindowControlBar: " + mControlBar);
		if (mControlBar == null)
			return;

		mControlBar.setVisibility(View.GONE);
		mWindowManager.addView(mControlBar,
				getMultiWindowControlBarLayoutParams());

		mMiniLauncher.setVisibility(View.GONE);
		mWindowManager.addView(mMiniLauncher, getMiniLauncherLayoutParams());

		mDragControl.setVisibility(View.GONE);
		mWindowManager.addView(mDragControl,
				getMultiWindowDragControlLayoutParams());

		mFloatingControl.setVisibility(View.GONE);
		mWindowManager.addView(mFloatingControl,
				getMultiWindowFloatingControlLayoutParams());
	}

	private WindowManager.LayoutParams getMultiWindowControlBarLayoutParams() {
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
				WindowManager.LayoutParams.TYPE_MULTIWINDOW_CONTROL, 0
						| WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
						| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
						| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
						| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
						| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
				PixelFormat.TRANSLUCENT);

		if (ActivityManager.isHighEndGfx()) {
			lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
		}

		lp.setTitle("MultiWindowControlBar");
		lp.windowAnimations = 0;
		return lp;
	}

	private WindowManager.LayoutParams getMiniLauncherLayoutParams() {
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
				WindowManager.LayoutParams.TYPE_MULTIWINDOW_MINILAUNCHER,
				0 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
				PixelFormat.TRANSLUCENT);

		if (ActivityManager.isHighEndGfx()) {
			lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
		}

		lp.setTitle("MiniLauncher");
		lp.windowAnimations = 0;
		return lp;
	}

	private WindowManager.LayoutParams getMultiWindowDragControlLayoutParams() {
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
				WindowManager.LayoutParams.TYPE_MULTIWINDOW_DRAGCONTROL, 0
						| WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
						| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
						| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
						| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
						| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
				PixelFormat.TRANSLUCENT);

		if (ActivityManager.isHighEndGfx()) {
			lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
		}

		lp.setTitle("MultiWindowDragControl");
		lp.windowAnimations = 0;
		return lp;
	}

	private WindowManager.LayoutParams getMultiWindowFloatingControlLayoutParams() {
		WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
				WindowManager.LayoutParams.TYPE_MULTIWINDOW_FLOATINGCONTROL, 0
						| WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
						| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
						| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
						| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
						| WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
				PixelFormat.TRANSLUCENT);

		if (ActivityManager.isHighEndGfx()) {
			lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
		}

		lp.setTitle("MultiWindowFloatingControl");
		lp.windowAnimations = 0;
		return lp;
	}

}
